﻿//-----------------------------------------------------------------------
// <copyright file="Rental.cs" company="SoSoft">
//     Copyright (c) SoSoft . All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace FirstSample
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    /// <summary>
    /// Rental Class 表示“某个顾客租了一个影片”
    /// </summary>
    public class Rental
    {
        /// <summary>
        /// Initializes a new instance of the Rental class.
        /// </summary>
        /// <param name="movie">rental movie</param>
        /// <param name="daysRented">days rented</param>
        public Rental(Movie movie, int daysRented)
        {
            if (movie == null)
            {
                throw new ArgumentNullException("movie");
            }
            this.Movie = movie;
            this.DaysRented = daysRented;
        }

        /// <summary>
        /// Gets or sets Rented movie.
        /// </summary>
        public Movie Movie { get; set; }

        /// <summary>
        /// Gets or setsRented days.
        /// </summary>
        public int DaysRented { get; set; }

        public double GetCharge()
        {
            double result = 0;
            switch (this.Movie.PriceCode)
            {
                // 取得影片出租价格
                case Movie.Regular:
                    result += 2;
                    if (this.DaysRented > 2)
                    {
                        result += (this.DaysRented - 2) * 1.5;
                    }
                    break;

                case Movie.NewRelease:
                    result += this.DaysRented * 3;
                    break;

                case Movie.ChildMovie:
                    result += 1.5;
                    if (this.DaysRented > 3)
                    {
                        result += (this.DaysRented - 3) * 1.5;
                    }
                    break;

                default:
                    new NotImplementedException();
                    break;
            }
            return result;
        }


        public int GetFrequentRenterPoints()
        {
            // add frequent renter points 累加常客积点

            // add bonusfor two day new release rental
            if (this.Movie.PriceCode == Movie.NewRelease &&
                this.DaysRented > 1)
            {
                return 2;
            }
         
            return 1;
        }
    }
}
